package cn.jzq.kotoba.modules.designpattern.observer.weather;

import java.util.Observable;
import java.util.Observer;

/**
 * @author jzq
 * @date 2018/12/21 9:59
 */
public class CurrentConditionsDisplay2 implements Observer, DisplayElment {
    Observable observable;

    private Double temp;

    private Double humidity;

    public CurrentConditionsDisplay2(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println("current conditions: " + this.temp + " C degrees and " + humidity + "% humidity");
    }

    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof WeatherData2) {
            WeatherData2 weatherData2 = (WeatherData2) o;
            this.temp = weatherData2.getTemp();
            this.humidity = weatherData2.getHumidity();
            display();
        }
    }
}
